package com.jstyle.jclife.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.jstyle.jclife.R;
import com.jstyle.jclife.utils.SharedPreferenceUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WorkOutSettingActivity extends AppCompatActivity {

    @BindView(R.id.iv_breath_setting_off)
    ImageView ivBreathSettingOff;
    @BindView(R.id.tv_level)
    TextView tvLevel;
    @BindView(R.id.radioButton_Beginner)
    RadioButton radioButtonBeginner;
    @BindView(R.id.radioButton_Junior)
    RadioButton radioButtonJunior;
    @BindView(R.id.radioButton_Skilled)
    RadioButton radioButtonSkilled;
    @BindView(R.id.radioGroup_level)
    RadioGroup radioGroupLevel;
    @BindView(R.id.tv_duration)
    TextView tvDuration;
    @BindView(R.id.radioButton_duration1)
    RadioButton radioButtonDuration1;
    @BindView(R.id.radioButton_duration2)
    RadioButton radioButtonDuration2;
    @BindView(R.id.radioButton_duration3)
    RadioButton radioButtonDuration3;
    @BindView(R.id.radioGroup_duration)
    RadioGroup radioGroupDuration;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_out_setting);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        float cal=SharedPreferenceUtils.getFloat(WorkOutActivity.KEY_WORKOUT_CAL,180);
        int time=SharedPreferenceUtils.getInteger(WorkOutActivity.KEY_WORKOUT_TIME,1);
        if(time==1){
            radioGroupLevel.check(R.id.radioButton_Beginner);
        }else if(time==2){
            radioGroupLevel.check(R.id.radioButton_Junior);
        }else {
            radioGroupLevel.check(R.id.radioButton_Skilled);
        }
        if(cal==180){
            radioGroupDuration.check(R.id.radioButton_duration1);
        }else if(cal==360){
            radioGroupDuration.check(R.id.radioButton_duration1);
        }else {
            radioGroupDuration.check(R.id.radioButton_duration2);
        }
        radioGroupLevel.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int time=1;
                switch (checkedId){
                    case R.id.radioButton_Beginner:
                        time=1;
                        break;
                    case R.id.radioButton_Junior:
                        time=2;
                        break;
                    case R.id.radioButton_Skilled:
                        time=3;
                        break;
                }
                SharedPreferenceUtils.setSpInteger(WorkOutActivity.KEY_WORKOUT_TIME,time);
            }
        });
        radioGroupDuration.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                float cal=180;
                switch (checkedId){
                    case R.id.radioButton_duration1:
                        cal=180;
                        break;
                    case R.id.radioButton_duration2:
                        cal=360;
                        break;
                    case R.id.radioButton_duration3:
                        cal=540;
                        break;
                }
                SharedPreferenceUtils.setSpFloat(WorkOutActivity.KEY_WORKOUT_CAL,cal);
            }
        });
    }

    @OnClick(R.id.iv_breath_setting_off)
    public void onViewClicked() {
        finish();
    }
}
